package m3f.retrieval;

import org.jblas.DoubleMatrix;

import m3f.computing.ConcurrentTemplate;
import m3f.data.SingleDataProvider;
import m3f.matrix.Minibatch;

public class ConcurrentRank extends ConcurrentTemplate {
	
	private SingleDataProvider database;
	private DoubleMatrix queries;
	private Rank.SimilarityMeasure measure;
	public DoubleMatrix R;
	
	
	public ConcurrentRank(SingleDataProvider database, DoubleMatrix queries, Rank.SimilarityMeasure measure){
		super(database.matrixRows()/database.getMinibatchSize()+1);
		this.database = database;
		this.queries = queries;
		this.measure = measure;
		Rank.initMatrix();
	}
	
	@Override
	public void singleOperation(int reg) {
		Minibatch db;
		synchronized(database){
			db = database.next();  
		}
		if (db != null){
			System.out.println("Minibatch " + db.getId());
			Rank.rank(db.matrix(), queries, measure, db.getId());		
		}

	}
	
}
